package com.maybach.core.flow.handler;

import com.maybach.common.enums.PartnerTypeEnum;
import com.maybach.common.model.PartnerDO;
import com.maybach.common.po.ProviderCertificatePO;
import com.maybach.core.manager.PartnerManager;
import com.maybach.util.AssertUtil;
import com.maybach.util.ImgUrlUtil;
import com.maybach.workflow.common.api.IFlowHandler;
import com.maybach.workflow.common.api.WorkFlowContext;
import com.maybach.workflow.common.api.enums.WFContextKeyEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by houenxun on 16/1/28.
 * <p/>
 * 完成企业信息认证进行后续操作，将身份证等个人信息拷贝的个人表中
 */
@Component
public class FinishProviderCertificate extends FinishSimpleFlow implements IFlowHandler {
    @Autowired
    protected PartnerManager partnerManager;


    @Override
    public void handle(WorkFlowContext context) {
        super.handle(context);
        ProviderCertificatePO certificatePO = (ProviderCertificatePO) context.getBizData().get(WFContextKeyEnum.flowApplyContent.name());
        AssertUtil.notNull(certificatePO, "PersonCertificatePO by flowId=" + context.getThisFlow().getId());
        PartnerDO partnerDO = partnerManager.selectByPrimaryKey(certificatePO.getPartnerId());
        partnerDO.setType(PartnerTypeEnum.dealerAndProvider.getCode());
        partnerDO.setContractImgs(ImgUrlUtil.mergeList(certificatePO.getContractImgs()));
        partnerManager.updateByPrimaryKeySelective(partnerDO);
    }

    @Override
    protected String getHandlerKey() {
        return "provider";
    }
}
